!!!
%html
  %body
    :javascript
      $(document).ready(function() {
            $("#hf_form").submit(function(e){
                //retrieve selected index value
                var hashFile = $('#hash_file option:selected').val();
                var action = $(this).attr('action');
                //perform conditional checks on Index value
                if(hashFile == 'add_new' && action != '/customers/upload/hashfile')
                {
                  // prevent defaul submission flow and redirect
                  e.preventDefault(e);
                  $(this).attr('action', '/customers/upload/hashfile');
                  $(this).attr('enctype', 'multipart/form-data').submit();
                }
                else
                {
                  //allow parent to handle workflow
                }
            });
        });

      function showDiv() {
        var Index = document.hf_form.hash_file.options[document.hf_form.hash_file.selectedIndex].value
        if(Index == "add_new")
        {
          document.getElementById('hashfile_div').style.display = 'inline';
          document.getElementById('selectfile_div').style.display = 'none';
        }
        else
        {
          document.getElementById('hashfile_div').style.display = 'none';
          document.getElementById('selectfile_div').style.display = 'inline';
        }
      }
    

    .span15
      .container
        .col-md-12
          .row
            .page-header
              - if params[:edit] == '1'
                %h1 Edit Hashes for: #{@job.name}
              - else
                %h1 Assign Hashes for: #{@job.name}
            .row
              .col-md-10.pull-left
                Apply hashes to be cracked. You can either copy/paste the desired hashes below, upload a new hashfile, or select from an existing file.
            .page-header
#exTab2.container
  %ul.nav.nav-tabs
    %li.active
      %a{"data-toggle" => 'tab', href: '#1'} Individual Hashes
    %li
      %a{"data-toggle" => 'tab', href: '#2'} Hashfile
  .tab-content
    #1.tab-pane.active
      
      %br
      .col-md-8
        %form{name: 'individual_hashes_form', id: 'individual_hashes_form', class: 'form-horizontal', action: '/customers/upload/hashes', method: 'post'}
          .form-group
            %label.control-label.col-xs-2{for: ''} Name
            .col-xs-10
              %input{type: 'textbox', name: 'hashfile_name',  class: 'form-control'}
          .form-group
            %label.control-label.col-xs-2{for: ''} Hashes
            .col-xs-10
              %textarea{name: 'hashes', rows: '5', cols: '88', form: 'individual_hashes_form', class: 'form-control'}
          .form-group
            .col-xs-offset-2.col-xs-10
              %input{type: 'hidden', name: 'job_id', value: "#{params[:job_id].to_s}"}
              %input{type: 'hidden', name: 'customer_id', value: "#{params[:customer_id].to_s}"}
          .form-group
            .col-md-1.pull-right
              %button.btn.btn-primary{type: 'submit'} Submit
    #2.tab-pane
      
      %br
      .col-md-8

        - if !@hashfiles.empty?
          / IF triggered AFTER atleast one hash file is assigned to customer record
          %form{name: 'hf_form', id: 'hf_form', class: 'form-horizontal', action: '/jobs/assign_hashfile', method: 'post'}

            .form-group
              %label.control-label.col-xs-2{for: ''} Hash Files
              .col-xs-8
                %select.form-control{id: 'hash_file', name: 'hash_file', onchange: 'showDiv()'}
                  - @hashfiles.each do |hashfile|
                    - if params[:edit] == '1'
                      - if @job.hashfile_id == hashfile.id
                        %option{value: "#{hashfile.id}", name: 'hashfile_id', type: 'button', selected: 'selected'} #{hashfile.name} - #{@cracked_status[hashfile.id]}
                      - else
                        %option{value: "#{hashfile.id}", name: 'hashfile_id', type: 'button'} #{hashfile.name} - #{@cracked_status[hashfile.id]}
                    - else
                      %option{value: "#{hashfile.id}", name: 'hashfile_id', type: 'button'} #{hashfile.name} - #{@cracked_status[hashfile.id]}
                  %option{value: 'add_new', name: 'hashfile_id', type: 'button'} New Hashfile 
            .section
              %div{class: "label_leftalign field"}
                #selectfile_div{style: "display:inline"}
                  .form-group
                    .col-xs-offset-2.col-xs-8
                      %input{type: 'hidden', name: 'job_id', value: "#{params[:job_id].to_s}"}
                      %input{type: 'hidden', name: 'customer_id', value: "#{params[:customer_id].to_s}"}
                      %input{type: 'hidden', name: 'form_id', value: '2'}
                      %br
                      - if params[:edit] == '1'
                        %input{type: 'hidden', name: 'edit', value: "#{params[:edit].to_s}"}
                        %button.btn.btn-primary{type: 'submit'} Update
                      - else
                        .col-md-1.pull-right
                          %button.btn.btn-primary{type: 'submit'} Select
                
                #hashfile_div{style: "display:none"}
                  %form{method: 'post', class: 'form-horizontal', action: '/customers/upload/hashfile', enctype: 'multipart/form-data'}
                    .form-group
                      %label.control-label.col-xs-2 Name:
                      .col-xs-10
                        %input{type: 'textbox', name: 'hashfile_name', id: 'hashfile_name'}
                    .form-group
                      %label.control-label.col-xs-2 Hash File:
                      .col-xs-10
                        %input{type: 'file', name: 'file', id: 'fileUp', class: 'inputFiles_cust', onchange: 'setFileName()'}
                        %br
                        Note: Hashview currently supports the following file types: pwdump, shadow, newline seperated
                        %input{type: 'hidden', name: 'job_id', value: "#{params[:job_id].to_s}"}
                        %input{type: 'hidden', name: 'customer_id', value: "#{params[:customer_id].to_s}"}
                        %input{type: 'hidden', name: 'form_id', value: '2'}
                    .form-group
                      .col-xs-offset-2.col-xs-10
                        .col-xs-3.pull-right
                          %button.btn.btn-primary{type: 'submit'} Upload

        - else
          / ELSE triggered if NO hash files have ever been uploaded
          / OOTB state      
          %form{method: 'post', class: 'form-horizontal', action: '/customers/upload/hashfile', enctype: 'multipart/form-data'}
            .form-group
              %label.control-label.col-xs-2{for: ''} Name
              .col-xs-10
                %input{type: 'textbox', name: 'hashfile_name', id: 'hashfile_name'}
            
            .form-group
              %label.control-label.col-xs-2{for: ''} Hash File
              .col-xs-10
                %input{type: 'file', name: 'file',id: 'fileUp', class: 'inputFiles_cust', onchange: 'setFileName()'}
                %input{type: 'hidden', name: 'job_id', value: "#{params[:job_id].to_s}"}
                %input{type: 'hidden', name: 'customer_id', value: "#{params[:customer_id].to_s}"}
                %input{type: 'hidden', name: 'form_id', value: '2'}

            .form-group
              .col-xs-offset-2.col-xs-10
                .col-md-1.pull-right
                  %button.btn.btn-primary{type: 'submit'} Upload
